package app.mvc.controller.editor
{
	import app.consts.CommandType;
	import app.interfaces.IEditorCommand;
	import app.mvc.AppFacade;
	import app.mvc.Notifications;
	import app.mvc.model.VO.UIObjectVO;
	import app.mvc.model.proxys.EditorDataProxy;
	import app.mvc.view.mediators.ObjectsViewMediator;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import utils.UtilsObjects;
	
	public class RemoveObjectCommand extends EditorBaseCommand implements ICommand, IEditorCommand
	{
		private var deletedObjects:Vector.<UIObjectVO> = new Vector.<UIObjectVO>();
		public function RemoveObjectCommand()
		{
			super();
		}		
		
		override public function redo():void
		{
			super.redo();
			execute(_notification);
		}
		
		override public function undo():void
		{
			super.undo();
		
			
			var uiObjectVO:UIObjectVO= null;
			var len:int = deletedObjects.length;
			var objectM:ObjectsViewMediator = facade.retrieveMediator(ObjectsViewMediator.NAME) as ObjectsViewMediator;
			var paramObj:Object=null;
			for(var i:int=0;i<len;++i)
			{
				uiObjectVO = deletedObjects[i];
				paramObj = {};
				paramObj.label = uiObjectVO.label;
				paramObj.x = uiObjectVO.x;
				paramObj.y = uiObjectVO.y;
				paramObj.uid = uiObjectVO.uid;
				
				AppFacade.getInstance().sendNotification(Notifications.CMD_TO_ADD_OBJECT,paramObj,CommandType.UNDO);
			}

			
		}
		
		override public function execute(notification:INotification):void
		{
			// TODO Auto Generated method stub
			super.execute(notification);
			var array:Array = notification.getBody() as Array;
			var len:int = array.length;
			for(var i:int=0;i<len;++i)
			{
				EditorDataProxy.getInstance().removeObject(array[i]);
				deletedObjects.push(UtilsObjects.getUIVoByUID(array[i]));
			}
			
			AppFacade.getInstance().sendNotification(Notifications.TO_REMOVE_OBJECT,array);
		}
		
	}
}